//SRF unit

#ifndef __SRF_H__
#define __SRF_H__

#include "SRF_sub.h"
#include "LRF.h"

//SRF unit
#define SRF_CLIENTS 14	// 8 Clusters, 1 Micro Controller, 1 Host, 2 Memory Data, 2 Memory Index Streams
#define SRF_STREAMS 8

#define SRF_WRITE 10
#define SRF_READ 20

#define SRF_NOP 0
#define SRF_WRITE_CHAR 1
#define SRF_WRITE_INT 2
#define SRF_WRITE_FLOAT 3
#define SRF_READ_CHAR 4
#define SRF_READ_INT 5
#define SRF_READ_FLOAT 6

#define SRF_DELAY 1

#define STREAM0 0
#define STREAM1 8000

class SRF
{

public:
	SRF();
	int update();
	int update(int client_num);
	int set_client(int client_num, int stream, int mem_loc, unsigned char input, int op_code);
	int set_client(int client_num, int stream, int mem_loc, int input, int op_code);
	int set_client(int client_num, int stream, int mem_loc, float input, int op_code);
	bool isReady(int client_num);
	int getOutput(int client_num, unsigned char& rv);
	int getOutput(int client_num, int& rv);
	int getOutput(int client_num, float& rv);
	void data_in(LRF* lrf[8], int lrf_loc);
	void data_out(LRF* lrf[8], int lrf_loc);
	void init_data_in(unsigned char * init, unsigned int init_size);
	void get_data_out(unsigned char * init, unsigned int init_size);


private:
	SRF_sub* srf_bank[SRF_STREAMS];
	int CyclesLeft[SRF_CLIENTS];
	bool Ready[SRF_CLIENTS];
	int opCode[SRF_CLIENTS];
	int loc[SRF_CLIENTS];
	int input_int[SRF_CLIENTS];
	unsigned char input_char[SRF_CLIENTS];
	float input_float[SRF_CLIENTS];
	int output_int[SRF_CLIENTS];
	unsigned char output_char[SRF_CLIENTS];
	float output_float[SRF_CLIENTS];
	int stream_num[SRF_CLIENTS];
	int stream_ptr[2];
};

#endif